import { useEffect, useRef, useState } from "react"; import { LeftBar } from "@/components/manga/leftBar"; import { useRouter } from "next/router"; import RightBar from "@/components/manga/rightBar"; import FirstPanel from "@/components/manga/panels/firstPanel"; import SecondPanel from "@/components/manga/panels/secondPanel"; import ThirdPanel from "@/components/manga/panels/thirdPanel"; import { getServerSession } from "next-auth"; import { authOptions } from "../../../api/auth/[...nextauth]"; import BottomBar from "@/components/manga/mobile/bottomBar"; import TopBar from "@/components/manga/mobile/topBar"; import Head from "next/head"; import ShortCutModal from "@/components/manga/modals/shortcutModal"; import ChapterModal from "@/components/manga/modals/chapterModal"; // import getConsumetPages from "@/lib/consumet/manga/getPage"; import { mediaInfoQuery } from "@/lib/graphql/query"; // import { redis } from "@/lib/redis"; // import getConsumetChapters from "@/lib/consumet/manga/getChapters"; import { toast } from "sonner"; import axios from "axios"; import { redis } from "@/lib/redis"; import getAnifyInfo from "@/lib/anify/info"; export default function Read({ data, info, chaptersData, currentId, sessions, provider, mangaDexId, number, }) { const [chapter, setChapter] = useState([]); const [layout, setLayout] = useState(1); const [visible, setVisible] = useState(true); const [mobileVisible, setMobileVisible] = useState(true); const [isKeyOpen, setIsKeyOpen] = useState(false); const [isChapOpen, setIsChapOpen] = useState(false); const [seekPage, setSeekPage] = useState(0); const [paddingX, setPaddingX] = useState(208); const [scaleImg, setScaleImg] = useState(1); const [nextChapter, setNextChapter] = useState(null); const [prevChapter, setPrevChapter] = useState(null); const [currentChapter, setCurrentChapter] = useState(null); const [currentPage, setCurrentPage] = useState(0); const hasRun = useRef(false); const router = useRouter(); // console.log({ info }); useEffect(() => { toast.message("This page is still under development", { description: "If you found any bugs, please report it to us!", position: "top-center", duration: 10000, }); }, []); useEffect(() => { hasRun.current = false; const chapters = chaptersData.find((x) => x.providerId === provider); const currentChapter = chapters.chapters?.find((x) => x.id === currentId); setCurrentChapter(currentChapter); setChapter(chapters); if (Array.isArray(chapters?.chapters)) { const currentIndex = chapters.chapters.findIndex( (chapter) => chapter.id === currentId ); if (currentIndex !== -1) { const nextChapter = chapters.chapters[currentIndex - 1]; const prevChapter = chapters.chapters[currentIndex + 1]; setNextChapter(nextChapter ? nextChapter : null); setPrevChapter(prevChapter ? prevChapter : null); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentId]); useEffect(() => { const handleKeyDown = (event) => { event.preventDefault(); if (event.key === "ArrowRight" && event.ctrlKey && nextChapter?.id) { router.push( `/en/manga/read/${ chapter.providerId }?id=${mangaDexId}&chapterId=${encodeURIComponent(nextChapter?.id)}${ info?.id?.length > 6 ? "" : `&anilist=${info?.id}` }&num=${nextChapter?.number}` ); } else if ( event.key === "ArrowLeft" && event.ctrlKey && prevChapter?.id ) { router.push( `/en/manga/read/${ chapter.providerId }?id=${mangaDexId}&chapterId=${encodeURIComponent(prevChapter?.id)}${ info?.id?.length > 6 ? "" : `&anilist=${info?.id}` }&num=${prevChapter?.number}` ); } if (event.code === "Slash" && event.ctrlKey) { setIsKeyOpen(!isKeyOpen); } if (event.key === "f" || event.key === "F") { setVisible(!visible); } if (event.code === "ArrowUp" && event.shiftKey) { setPaddingX(paddingX - 50); } else if (event.code === "ArrowDown" && event.shiftKey) { setPaddingX(paddingX + 50); } }; window.addEventListener("keydown", handleKeyDown); return () => { window.removeEventListener("keydown", handleKeyDown); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [nextChapter?.id, prevChapter?.id, visible, isKeyOpen, paddingX]); return ( <>